<?php
namespace Fiestissima\CRM\Controller;

use Symfony\Bundle\FrameworkBundle\Controller\Controller;

class DiarioController extends Controller
{	
	public function getDiarioAction($year, $month, $day)
	{
		//gets the diario for the given date
		//if date is 0/0/0 todays diario is retrieved
		
		if($year == 0){
			$fecha = date("Y").'-'.date("m").'-'.date("d");
		}else{
			
			$fecha = $year.'-'.$month.'-'.$day;
		}
		
		$repository = $this->getDoctrine()->getRepository('FiestissimaCRM:Diario');
		$diario = $repository->findBy(array('d_fecha'=> $fecha));
		
		return $this->render('FiestissimaCRM:Default:diario.html.php', array('diario' => $diario, 'fecha' => $fecha));

		
		//return $this->render('FiestissimaCRM:Default:diario.html.php', array('fecha' => $fecha));
	}
	
	public function createDiarioAction()
	{
// 		$repository = $this->getDoctrine()->getRepository('FiestissimaCRM:Product');
// 		$products = $repository->findBy(array(), array('pr_nombre' => 'ASC'));
		
		$form = $this->createFormBuilder()
				->add('task', 'text')
				->add('dueDate', 'date')
				->add('save', 'submit')
				->getForm();
		
		return $this->render('FiestissimaCRM:Default:diario.add.html.php', array('form' => $form->createView()));
	}
	
	public function responseDiarioAction(Request $request)
	{
		
		return $this->render('FiestissimaCRM:Default:diario.response.html.php');
	}
}